package validates

import (
	"github.com/kataras/iris/v12"
)

// 登录请求验证
type loginRequest struct {
	Username string `json:"username" validate:"required"`
	Password string `json:"password" validate:"required"`
}

// Trans 自定义错误消息
func (r *loginRequest) Trans() map[string]string {
	m := make(map[string]string)
	m["Username.required"] = "用户名必传"
	m["Password.required"] = "密码必传"

	return m
}

// LoginRequestValidate 进行验证
func LoginRequestValidate(ctx iris.Context) error {
	loginValidate := loginRequest{
		Username: ctx.PostValueTrim("username"),
		Password: ctx.PostValueTrim("password"),
	}

	return Run(&loginValidate)
}
